#include <iostream>
#include <fstream>
#include <chrono>
#include <cmath>
using namespace std;
void bubble_sort(int numbers[5000]) {
    bool flag;
    for (int i = 0; i < 5000 - 1; i++) {
        flag = false;
        for (int j = 0; j < 5000 - 1; j++) {
            if (numbers[j] > numbers[j + 1]) {
                swap(numbers[j], numbers[j + 1]);
                flag = true;
            }
        }
        if (!flag) break;
    }
}

int main() {
    ifstream input_file;
    string files[3] = {"m1_sorted.txt", "m2_reverse.txt", "m3_shuffle.txt"};

    for (int i = 0; i < 3; i++) {
        input_file.open(files[i]);

        int values[5000];
        int value;
        int j = 0;
        while (input_file >> value) {
            values[j] = value;
            j ++;
        }
        input_file.close();

        auto start = chrono::high_resolution_clock::now();
        bubble_sort(values);
        auto end = chrono::high_resolution_clock::now();

        chrono::duration<double, milli> duration = end - start;
        std::cout << files[i].substr(0, files[i].length()-4) << " " << floor(duration.count()) << " milliseconds" << std::endl;
    }

    return 0;
}
